﻿/// <reference path="../../../../SIR.Web/scripts/_references.js" />
/// <reference path="../../../../SIR.Web/scripts/jquery-1.9.1.js" />
/// <reference path="../../../../SIR.Web/scripts/angular.js" />
/// <reference path="../../../../SIR.Web/scripts/angular-mocks.js" />
/// <reference path="../../../../SIR.Web/scripts/modal.js" />
/// <reference path="../../../../SIR.Web/scripts/slider.js" />
/// <reference path="../../../../SIR.Web/scripts/timer.js" />

/// <reference path="../../../../SIR.Web/app/app.js" />
/// <reference path="../../../../SIR.Web/app/common/common.js" />
/// <reference path="../../../../SIR.Web.Tests/JavaScript/sir-mock.js" />
/// <reference path="../../../../SIR.Web/app/search/search.js" />
/// <reference path="../../../../SIR.Web/app/user/user.js" />
/// <reference path="../../../../SIR.Web/app/authenticate/authenticate.js" />
/// <reference path="../../../../SIR.Web/app/authenticate/services/auth-service.js" />
/// <reference path="../../../../SIR.Web/app/common/services/data-service.js" />
/// <reference path="../../../../SIR.Web/app/common/services/upload-service.js" />
/// <reference path="../../../../SIR.Web/app/user/services/library-service.js" />
/// <reference path="../../../../SIR.Web/app/user/services/library-mediator.js" />
/// <reference path="../../../../SIR.Web/app/user/controllers/user-controller.js" />
/// <reference path="../../../../SIR.Web/app/user/controllers/user-image-upload-controller.js" />
/// <reference path="../../../../SIR.Web/app/user/controllers/user-library-controller.js" />
/// <reference path="../../../../SIR.Web/app/user/controllers/user-library-folder-controller.js" />
/// <reference path="../../../../SIR.Web/app/user/controllers/user-library-image-container-controller.js" />
/// <reference path="../../../../SIR.Web/app/user/controllers/user-view-images-controller.js" />
/// <reference path="../../../../SIR.Web/app/user/controllers/user-view-favorites-controller.js" />

describe('User Controllers:', function () { 
	'use strict';
	// initialize variables and modules
	var scope, searchController,
		userController, libraryController,
		imageContainerController, viewImagesController,
		folderController,
    	mockLibraryService, mockAuthService,
		mockState, mockDataService, notifyService, mockLibraryMediator;
	
	beforeEach(module('ui.router'));
	beforeEach(module('ui.slider'));
	beforeEach(module('app.common'));
	beforeEach(module('app.user'));
	beforeEach(module('app.authenticate'));
	beforeEach(module('app'));

	beforeEach(inject(function ($controller, $rootScope, notify) {
		// intialize the variables for each test
		notifyService = notify;
		// create mock data service
		mockDataService = {
			download: function () {
				return {
					then: function (callback) {
						callback({ data: { Successful: true, Content: [{}] } });
					}
				};
			}
		};
		// create mock mediator
		mockLibraryMediator = {
			imageContainerController: {},
			uploadController: {},
			folderController: {},
			// sets the image container controller reference
			setImageContainerController: function (controller) {
				this.imageContainerController = controller;
			},
			// sets the upload controller reference
			setUploadController: function (controller) {
				this.uploadController = controller;
			},
			// sets the folder controller reference
			setFolderController: function (controller) {
				this.folderController = controller;
			},
			// submit the rename for a folder through the upload service
			renameFolder: function (folder) {
				mockDataService.upload('Folder', { Id: folder.Id, Name: folder.newName })
					.then(mockLibraryMediator.folderController.handleRenameFolderResponse);
			}
		};
		// create mock auth service
		mockAuthService = {
			authStatus: { isAuthenticated: false, authenticatedUser: null },
			sendAuthRequest: function () {
				return {
					then: function (callback) {
					}
				}
			}
		};
		// create mock state
		mockState = {
			params: {},
			transitionTo: function () { }
		};
		// new scope
		scope = $rootScope.$new();
		// create user controller
		userController = $controller('UserController', {
			$scope: scope,
			libraryService: mockLibraryService,
			authService: mockAuthService,
			$state: mockState,
			$stateParams: {},
			dataService: mockDataService
		});
		// create library controller
		libraryController = $controller('UserLibraryController', {
			$scope: scope,
			dataService: mockDataService,
			libraryMediator: mockLibraryMediator,
		});
		// create image container controller
		imageContainerController = $controller('UserLibraryImageContainerController', {
			$scope: scope,
			dataService: mockDataService
		});
		// create view images controller
		viewImagesController = $controller('UserViewImagesController', {
			$scope: scope,
			libraryService: mockLibraryService,
			dataService: mockDataService
		});
		// create folder controller
		folderController = $controller('UserLibraryFolderController', {
			$scope: scope, 
			libraryService: mockLibraryService, 
			$state: mockState,
			dataService: mockDataService,
			libraryMediator: mockLibraryMediator
		});
		// spy on the notify service to verify messages were called
		spyOn(notifyService, 'success').andCallThrough();
		spyOn(notifyService, 'info').andCallThrough();
		spyOn(notifyService, 'warning').andCallThrough();
		spyOn(notifyService, 'error').andCallThrough();
	}));

    describe('Controller - User Create Folder (Total: 3)', function () {
    	it('[1] Produce \'Invalid password\' message when user enters a valid email and an invalid password to create a folder', function () {
			// watch create folder response handler
    		spyOn(folderController, 'handleCreateNewFolderResponse').andCallThrough();
			// mock data service to return error
        	mockDataService.upload = function () {
        		return {
        			then: function (callback) {
        				callback({ data: { Successful: false, Message: 'User must be authenticated' } });
        			}
        		}
        	};
			// set model for new folder
        	scope.folderModel.newFolderName = 'New Folder';
        	scope.folderModel.currentFolder = { Id: -1 };
			// submit create folder
        	scope.submitCreateNewFolder();
			// expect the handler was called and the error was displayed
        	expect(folderController.handleCreateNewFolderResponse).toHaveBeenCalled();
        	expect(notifyService.error).toHaveBeenCalledWith('User must be authenticated');
        });

    	it('[2] Produce \'Create folder\' with the name "New Folder"', function () {
			// spy on the handler
    		spyOn(folderController, 'handleCreateNewFolderResponse').andCallThrough();
			// create the new folder response
    		var newFolder = { Name: 'New Folder' };
			// configure the data service to return the new folder
        	mockDataService.upload = function () {
        		return {
        			then: function (callback) {
        				callback({ data: { Successful: true, Message: '', Content: newFolder } });
        			}
        		}
        	};
			// set the new folder fields
        	scope.folderModel.newFolderName = 'New Folder';
        	scope.folderModel.currentFolder = { Id: -1, path: '', Name: 'Library', Folders: [] };
			// submit the create new folder
        	scope.submitCreateNewFolder();
			// verify handler was called
        	expect(folderController.handleCreateNewFolderResponse).toHaveBeenCalled();
			// verify success message was shown
        	expect(notifyService.success).toHaveBeenCalledWith('Folder was created');
			// verify the folder was added underneat the root folder
        	expect(scope.folderModel.currentFolder.Folders.length).toBe(1);
			// verfy the path for the folder was set
        	expect(newFolder.path).toBe('Library/');
        });

    	it('[3] Produce \'Create folder\' with the name "My Pictures"', function () {
			// spy on the response handler
    		spyOn(folderController, 'handleCreateNewFolderResponse').andCallThrough();
			// create response folder
    		var newFolder = { Name: 'New Folder' };
			// configure service to return the response
        	mockDataService.upload = function () {
        		return {
        			then: function (callback) {
        				callback({ data: { Successful: true, Message: 'User must be authenticated', Content: newFolder } });
        			}
        		}
        	};
			// set model fields
        	scope.folderModel.newFolderName = 'New Folder';
			// set the current folder
        	scope.folderModel.currentFolder = { Id: -1, path: 'Library/', Name: 'Sub Folder', Folders: [] };
			// submit create folder
        	scope.submitCreateNewFolder();
			// expect the response was received
        	expect(folderController.handleCreateNewFolderResponse).toHaveBeenCalled();
			// verify message was shown
        	expect(notifyService.success).toHaveBeenCalledWith('Folder was created');
			// verify the folder was added underneath the current folder
        	expect(scope.folderModel.currentFolder.Folders.length).toBe(1);
			// verify that the path was set correct
        	expect(newFolder.path).toBe('Library/Sub Folder/');
        });

    });

    describe('Controller - User Move Image/Folder (Total: 5)', function () {
    	it('[1] Produce \'Invalid password\' message when user enters a valid email and an invalid password to move an image or folder', function () {
			// spy on move folder response
    		spyOn(folderController, 'handleMoveFolderResponse').andCallThrough();
			// set data service to return authenticate required response
        	mockDataService.upload = function () {
        		return {
        			then: function (callback) {
        				callback({ data: { Successful: false, Message: 'User must be authenticated' } });
        			}
        		}
        	};
			// set the current folder (destination folder) and the folder to move
        	scope.folderModel.moveFolder = { Id: -1, Name: 'Move Folder' };
        	scope.folderModel.currentFolder = { Id: -1, Name: 'To Folder' };
			// submit the move folder 
        	scope.submitMoveFolder();
			// expect that the handler was called
        	expect(folderController.handleMoveFolderResponse).toHaveBeenCalled();
			// expect that the error message was shown
        	expect(notifyService.error).toHaveBeenCalledWith('User must be authenticated');
        });

    	it('[2] Produce \'Move image\' with the name "Sample" to "Samples" folder', function () {
			// spy on the move image response
    		spyOn(imageContainerController, 'handleMoveImageResponse').andCallThrough();
			// spy on the events
        	spyOn(scope, 'notifyBeginMoveImage').andCallThrough();
        	spyOn(scope, 'notifyEndMoveImage').andCallThrough();
        	spyOn(scope.images, 'afterImageRemoved').andCallThrough();
			// intialize the move image
        	var moveImage = { Id: -1, Name: 'Name', newName: 'New Name', ParentFolderId: 0 };
			// add the image to the item list
        	scope.images.items.push(moveImage);
			// add the image to the page items
        	scope.images.pageItems.push(moveImage)
			// set the destination folder
        	scope.model.imageDestinationFolder = { Id: 1 };
			// set the data service to move the image
        	mockDataService.upload = function () {
        		return {
        			then: function (callback) {
        				callback({ data: { Successful: true, Message: '', Content: { Name: 'Name' } } });
        			}
        		}
        	};
			// start moving the image
        	scope.beginMovingImage(moveImage);
			// expect the notify event was called
        	expect(scope.notifyBeginMoveImage).toHaveBeenCalled();
			// submit the move image action
        	scope.submitMoveImage(moveImage);
			// expect the hanlder was called
        	expect(imageContainerController.handleMoveImageResponse).toHaveBeenCalled();
			// expect the image moved event was called
        	expect(scope.images.afterImageRemoved).toHaveBeenCalled();
			// expect the end move image event was called
        	expect(scope.notifyEndMoveImage).toHaveBeenCalled();
			// expect the image was removed from both lists
        	expect(scope.images.items.indexOf(moveImage)).toBe(-1);
        	expect(scope.images.pageItems.indexOf(moveImage)).toBe(-1);
        });

    	it('[3] Produce \'Move folder\' with the name "Samples" to "Folder" folder', function () {
			// spy on the move folder response
        	spyOn(folderController, 'handleMoveFolderResponse').andCallThrough();
			// set the 3rd level
        	var thirdLevel = { path: 'Library/Sub Folder/', Folders: [] };
			// set the 2nd level
        	var secondLevel = { Id: -1, path: 'Library/', Name: 'Sub Folder', Folders: [thirdLevel] };
			// set the library
        	var library = { Name: 'Library', path: '', Folders: [secondLevel] };
			// add the library to the folders model
        	scope.folderModel.folders = [library];
			// set the data service to return the thrid level
        	mockDataService.upload = function () {
        		return {
        			then: function (callback) {
        				callback({ data: { Successful: true, Message: 'Folder was moved', Content: thirdLevel } });
        			}
        		}
        	};
			// set the folder to be moved and the destination
        	scope.folderModel.currentFolder = library;
        	scope.folderModel.moveFolder = thirdLevel;
			// submit the move folder
        	scope.submitMoveFolder();
			// expect the hanlder was called
        	expect(folderController.handleMoveFolderResponse).toHaveBeenCalled();
			// expect the success message was called
        	expect(notifyService.success).toHaveBeenCalledWith('Folder was moved');
			// expect that the path was changed to the library
        	expect(thirdLevel.path).toBe('Library/');
			// expect that the 2nd level does not have subfolders
        	expect(secondLevel.Folders.length).toBe(0);
			// expect that the library contains two folders
        	expect(library.Folders.length).toBe(2);
        });

    	it('[4] Produce \'Move image\' with the name "Picture" to "Folder" folder', function () {
			// spy on the move folder response
    		spyOn(imageContainerController, 'handleMoveImageResponse').andCallThrough();
			// spy on the move image events
        	spyOn(scope, 'notifyBeginMoveImage').andCallThrough();
        	spyOn(scope, 'notifyEndMoveImage').andCallThrough();
        	spyOn(scope.images, 'afterImageRemoved').andCallThrough();
			// set the move image
        	var moveImage = { Id: -1, Name: 'Name', newName: 'New Name', ParentFolderId: 0 };
			// add the image to the items lists
        	scope.images.items.push(moveImage);
        	scope.images.pageItems.push(moveImage)
			// set the destination folder
        	scope.model.imageDestinationFolder = { Id: 1 };
			// set the upload function to return a successful response
        	mockDataService.upload = function () {
        		return {
        			then: function (callback) {
        				callback({ data: { Successful: true, Message: '', Content: { Name: 'Name' } } });
        			}
        		}
        	};
			// begin moving image
        	scope.beginMovingImage(moveImage);
			// expect the notify move image event was raised
        	expect(scope.notifyBeginMoveImage).toHaveBeenCalled();
			// submit move image
        	scope.submitMoveImage(moveImage);
			// expect the move image response was handled
        	expect(imageContainerController.handleMoveImageResponse).toHaveBeenCalled();
			// expect the image removed event to have been called
        	expect(scope.images.afterImageRemoved).toHaveBeenCalled();
			// Expect the end move image event to have been raised
        	expect(scope.notifyEndMoveImage).toHaveBeenCalled();
			// expect the image was removed from both items lists
        	expect(scope.images.items.indexOf(moveImage)).toBe(-1);
        	expect(scope.images.pageItems.indexOf(moveImage)).toBe(-1);
        });

    	it('[5] Produce \'Move folder\' with the name "Copy" to "Folder" folder', function () {
			// spy on the move folder response
        	spyOn(folderController, 'handleMoveFolderResponse').andCallThrough();
			// set up the folder structure
        	var fourthLevel = { path: 'Library/Sub Folder/Third', Folders: [] };
        	var thirdLevel = { Name: 'Third', path: 'Library/Sub Folder/', Folders: [fourthLevel] };
        	var secondLevel = { Id: -1, path: 'Library/', Name: 'Sub Folder', Folders: [thirdLevel] };
        	var library = { Name: 'Library', path: '', Folders: [secondLevel] };
			// set up the library
        	scope.folderModel.folders = [library];
			// set the successful response
        	mockDataService.upload = function () {
        		return {
        			then: function (callback) {
        				callback({ data: { Successful: true, Message: 'Folder was moved', Content: thirdLevel } });
        			}
        		}
        	};
			// move the 3rd level to the library
        	scope.folderModel.currentFolder = library;
        	scope.folderModel.moveFolder = thirdLevel;
        	scope.submitMoveFolder();
			// expect the response was handled
        	expect(folderController.handleMoveFolderResponse).toHaveBeenCalled();
			// expect the success message was sent
        	expect(notifyService.success).toHaveBeenCalledWith('Folder was moved');
			// expect the path was changed to the library
        	expect(thirdLevel.path).toBe('Library/');
			// expect the folder is gone from the second leve
        	expect(secondLevel.Folders.length).toBe(0);
			// expect the library now has two folders
        	expect(library.Folders.length).toBe(2);
			// expect the 4th level to have been moved with the 3rd
        	expect(thirdLevel.Folders.length).toBe(1);
			// expect the 4th level to have had the path changed too
        	expect(thirdLevel.Folders[0].path).toBe('Library/Third/');
        });
    });

    describe('Controller - User Rename Image/Folder (Total: 5)', function () {
    	it('[1] Produce \'Invalid password\' message when user enters a valid email and an invalid password to rename an image or folder', function () {
			// spy on the folder rename response
    		spyOn(folderController, 'handleRenameFolderResponse').andCallThrough();
			// set the data service to return an error
        	mockDataService.upload = function () {
        		return {
        			then: function (callback) {
        				callback({ data: { Successful: false, Message: 'User must be authenticated' } });
        			}
        		}
        	};
			// set the current folder
        	scope.model.currentFolder = { Id: -1, newName: 'New Folder Name', Name: 'New Folder Name' };
			// submit the rename
        	scope.submitRenameFolder();
			// expect the response was handled
        	expect(folderController.handleRenameFolderResponse).toHaveBeenCalled();
			// expect the error message was displayed
        	expect(notifyService.error).toHaveBeenCalledWith('User must be authenticated');
        });

    	it('[2] Produce \'Rename image\' with the name "Sample" to "Sample B"', function () {
			// spy on the response handler
    		spyOn(imageContainerController, 'handleRenameImageResponse').andCallThrough();
			// set the rename image object
        	var renameImage = { Id: -1, Name: 'Name', newName: 'New Name' };
			// set the data service to return the rename object
        	mockDataService.upload = function () {
        		return {
        			then: function (callback) {
        				callback({ data: { Successful: true, Message: '', Content: { Name: 'New Name' } } });
        			}
        		}
        	};
			// submit the rename
        	scope.submitRenameImage(renameImage);
			// expect the handler to have been called
        	expect(imageContainerController.handleRenameImageResponse).toHaveBeenCalled();
			// expect the name was changed
        	expect(renameImage.Name).toBe('New Name');
        });

    	it('[3] Produce \'Rename folder\' with the name "Samples" to "Folder B"', function () {
			// spy on the rename handler
    		spyOn(folderController, 'handleRenameFolderResponse').andCallThrough();
			// set the rename folder
        	var renameFolder = {
        		Id: -1, path: 'Library/', Name: 'Rename', Folders: [
					{ path: 'Library/Sub Folder/', Folders: [] }
        		]
        	};
			// set the data service to return the successful response
        	mockDataService.upload = function () {
        		return {
        			then: function (callback) {
        				callback({ data: { Successful: true, Message: 'Folder was renamed', Content: renameFolder } });
        			}
        		}
        	};
			// set the folders
        	scope.folderModel.folders = [{ Name: 'Library', path: '', Folders: [renameFolder] }];
			// set the current folder
        	scope.folderModel.currentFolder = renameFolder;
			// set the new name
        	scope.folderModel.currentFolder.newName = 'Rename';
			// submit the rename
        	scope.submitRenameFolder();
			// expect the response was handled
        	expect(folderController.handleRenameFolderResponse).toHaveBeenCalled();
			// expect the success message was shown
        	expect(notifyService.success).toHaveBeenCalledWith('Folder was renamed');
			// expect that the path for the sub folder was changed
        	expect(renameFolder.Folders[0].path).toBe('Library/Rename/');
        });

    	it('[4] Produce \'Error renaming image\' message with the name "Picture" to "Sample"', function () {
			// spy on the rename response
    		spyOn(imageContainerController, 'handleRenameImageResponse').andCallThrough();
			// set the image rename object
        	var renameImage = { Id: -1, Name: 'Name', newName: 'New Name' };
			// set the data service to return the failed response
        	mockDataService.upload = function () {
        		return {
        			then: function (callback) {
        				callback({ data: { Successful: false, Message: 'Failed', Content: { Name: 'New Name' } } });
        			}
        		}
        	};
			// submit the rename
        	scope.submitRenameImage(renameImage);
			// expect the response was handled
        	expect(imageContainerController.handleRenameImageResponse).toHaveBeenCalled();
			// expect the name didn't change
        	expect(renameImage.Name).toBe('Name');
        });

    	it('[5] Produce \'Error renaming folder\' message with the name "Copy" to "Samples" folder', function () {
			// spy on the folder rename response
    		spyOn(folderController, 'handleRenameFolderResponse').andCallThrough();
			// set the data service to return the error message
        	mockDataService.upload = function () {
        		return {
        			then: function (callback) {
        				callback({ data: { Successful: false, Message: 'The folder could not be renamed because a folder with the same name already exists' } });
        			}
        		}
        	};
			// set the current folder
        	scope.folderModel.currentFolder = { Id: -1, Name: 'New Folder Name', newName: 'New Folder Name' };
			// submit the rename
        	scope.submitRenameFolder();
			// expect the response to have been handled
        	expect(folderController.handleRenameFolderResponse).toHaveBeenCalled();
			// expect the error message was shown to the user
        	expect(notifyService.error).toHaveBeenCalledWith('The folder could not be renamed because a folder with the same name already exists');
        });
    });

    describe('Controller - User Delete Image/Folder (Total: 3)', function () {
        it('[1] Produce \'Invalid password\' message when user enters a valid email and an invalid password to delete an image or folder', function () {
			// spy on the remove folder response
        	spyOn(folderController, 'handleRemoveFolderResponse').andCallThrough();
			// set the data service to return the error message
        	mockDataService.upload = function () {
        		return {
        			then: function (callback) {
        				callback({ data: { Successful: false, Message: 'User must be authenticated', Content: [] } });
        			}
        		}
        	};
			// set the current folder
        	scope.model.currentFolder = { Id: -1, Name: 'New Folder Name' };
			// submit the remove folder action
        	scope.submitRemoveFolder();
			// expect the response to have been handled
        	expect(folderController.handleRemoveFolderResponse).toHaveBeenCalled();
			// expect the error message was shown to the user
        	expect(notifyService.error).toHaveBeenCalledWith('User must be authenticated');
        });

        it('[2] Produce \'Delete image\' with the name "Sample"', function () {
			// spy on the delete image handler
        	spyOn(imageContainerController, 'handleDeleteImageResponse').andCallThrough();
			// set the image to be removed
        	var renameImage = { Id: -1, Name: 'Name' };
			// add the image to the image lists
        	scope.images.items.push(renameImage);
        	scope.images.pageItems.push(renameImage);
			// set the data service to return a successful result
        	mockDataService.upload = function () {
        		return {
        			then: function (callback) {
        				callback({ data: { Successful: true, Message: '', Content: null } });
        			}
        		}
        	};
			// delete the image
        	scope.submitDeleteImage(renameImage);
			// expect the response was handled
        	expect(imageContainerController.handleDeleteImageResponse).toHaveBeenCalled();
			// expect the image was removed from both lists
        	expect(scope.images.items.indexOf(renameImage)).toBe(-1);
        	expect(scope.images.pageItems.indexOf(renameImage)).toBe(-1);
        });

        it('[3] Produce \'Delete folder\' with the name "Folder"', function () {
			// spy on the remove folder response handler
        	spyOn(folderController, 'handleRemoveFolderResponse').andCallThrough();
			// set the data service to return a successful response
        	mockDataService.upload = function () {
        		return {
        			then: function (callback) {
        				callback({ data: { Successful: true, Message: 'Folder was removed', Content: [] } });
        			}
        		}
        	};
			// set the folders list
        	scope.folderModel.folders = [{ Name: 'r', path: '', Folders: [{ Name: 'd', path: 'r/', unselect: function () { } }], select: function () { } }];
			// set the current folder
        	scope.model.currentFolder = scope.folderModel.folders[0].Folders[0];
        	scope.folderModel.currentFolder = scope.model.currentFolder;
			// submit the remove action
        	scope.submitRemoveFolder();
			// expect the response was handled
        	expect(folderController.handleRemoveFolderResponse).toHaveBeenCalled();
			// expect the message was displayed to the user
        	expect(notifyService.success).toHaveBeenCalledWith('Folder was removed');
			// expect the folder was removed from the parent folder
        	expect(scope.folderModel.folders[0].Folders.length).toBe(0);
        });
    });

    describe('Controller - User Change Privacy Settings (Test: 4)', function () {
        it('[1] Produce \'Invalid password\' message when user enters a valid email and an invalid password to change his or her privacy settings', function () {
			// set the upload service to return an error message
        	mockDataService.upload = function () {
        		return {
        			then: function (callback) {
        				callback({ data: { Successful: false, Message: 'User must be authenticated', Content: [] } });
        			}
        		}
        	};
			// set the current folder
        	scope.model.currentFolder = { Id: -1, Name: 'New Folder Name' };
			// submit the lock folder
        	scope.lockFolder(scope.model.currentFolder);
			// expect that the folder was not made private
        	expect(scope.model.currentFolder.IsPrivate).toBeFalsy();
        });

        it('[2] Produce \'Image privacy changed to private\'', function () {
			// set the data seervice to return a successful response
        	mockDataService.upload = function () {
        		return {
        			then: function (callback) {
        				callback({ data: { Successful: true, Message: '', Content: [] } });
        			}
        		}
        	};
			// set the image as not private
        	var image = { IsPrivate: false }
			// lock the image
        	scope.lockImage(image);
			// expect the folder to now be private
        	expect(image.IsPrivate).toBeTruthy();
        });

        it('[3] Produce \'Folder privacy changed to private\'', function () {
			// set the data service to return a successful response
        	mockDataService.upload = function () {
        		return {
        			then: function (callback) {
        				callback({ data: { Successful: true, Message: '', Content: [] } });
        			}
        		}
        	};
			// set the current folder as not private
        	scope.model.currentFolder = {
        		Id: -1, Name: 'New Folder Name', Folders: [{
        			IsParentFolderPrivate: false,
        			IsPrivate: false
        		}], Images: [{
        			IsFolderPrivate: false,
        			IsPrivate: false
        		}]
        	};
			// lock the current folder
        	scope.lockFolder(scope.model.currentFolder);
			// expect the folder to be private
        	expect(scope.model.currentFolder.IsPrivate).toBeTruthy();
			// expect the sub folder to be private but only by the parent being private
        	expect(scope.model.currentFolder.Folders[0].IsParentFolderPrivate).toBeTruthy();
        	expect(scope.model.currentFolder.Folders[0].IsPrivate).toBeFalsy();
			// expect the image is private because of the folder too
        	expect(scope.model.currentFolder.Images[0].IsFolderPrivate).toBeTruthy();
        	expect(scope.model.currentFolder.Images[0].IsPrivate).toBeFalsy();
        });

        it('[4] Produce \'Profile privacy changed to private\'', function () {
			// set the data service to return a successful result
        	mockDataService.upload = function () {
        		return {
        			then: function (callback) {
        				callback({ data: { Successful: true, Message: '', Content: [] } });
        			}
        		}
        	};
			// set the current folder with a private folder
        	scope.model.currentFolder = {
        		Id: -1, Name: 'New Folder Name', Folders: [{
        			IsParentFolderPrivate: false,
        			IsPrivate: true
        		}], Images: [{
        			IsFolderPrivate: false,
        			IsPrivate: false
        		}]
        	};
			// lock the folder
        	scope.lockFolder(scope.model.currentFolder);
			// expect the privacy to be set on the sub folders and images
        	expect(scope.model.currentFolder.IsPrivate).toBeTruthy();
        	expect(scope.model.currentFolder.Folders[0].IsParentFolderPrivate).toBeTruthy();
        	expect(scope.model.currentFolder.Folders[0].IsPrivate).toBeTruthy();
        	expect(scope.model.currentFolder.Images[0].IsFolderPrivate).toBeTruthy();
        	expect(scope.model.currentFolder.Images[0].IsPrivate).toBeFalsy();
			// unlock the folder
        	scope.unlockFolder(scope.model.currentFolder);
			// expect the subfolders and images to be "unlocked" but stay private if explictly set
        	expect(scope.model.currentFolder.IsPrivate).toBeFalsy();
        	expect(scope.model.currentFolder.Folders[0].IsParentFolderPrivate).toBeFalsy();
        	expect(scope.model.currentFolder.Folders[0].IsPrivate).toBeTruthy();
        	expect(scope.model.currentFolder.Images[0].IsFolderPrivate).toBeFalsy();
        	expect(scope.model.currentFolder.Images[0].IsPrivate).toBeFalsy();
        });
    });

});